Use rhai for most protocol implementations - #945
Draft
qdot wants to merge 7 commits into
Draft
Conversation
…er plumbing - Hardened shared rhai engine: no module resolution (import/eval rejected at parse time), operation/call-depth/size budgets - Fail-soft loader with structured per-file load report; duplicate protocol names resolve first-file-wins; missing dir is a no-op, unreadable/non-dir path errors - ScriptedProtocolHandler implements ProtocolHandler with per-connection state bound to this; strict command-map validation (endpoint, byte range, command id UUIDs); missing handlers map to UnhandledCommand, script errors to DeviceSpecificError with a stable 'Rhai protocol <name>: ' prefix - ServerDeviceManagerBuilder.script_protocol_directory option threaded into the device manager event loop; scripts override same-name built-ins - New ButtplugServerError::ScriptProtocolLoadError variant - ProtocolManager::from_map augmentation constructor - Unit tests covering registration/override, parity with the Rust aneros/ jejoue/maxpro impls, fail-soft loading, runtime error containment, op-limit termination, per-connection state isolation, and command-id semantics - Shipped script assets: aneros.rhai, jejoue.rhai, maxpro.rhai
…arness - DeviceTestCase gains optional script_protocol_directory, resolved relative to the crate manifest and applied to the ServerDeviceManagerBuilder in all five client version builders (v0-v4) - aneros and jejoue YAML cases point at the shipped script directory - new test_maxpro_protocol.yaml (CRC-bearing bytes from the maxpro impl) - new test_script_protocol.yaml: novel-name script protocol (scripttest) with its own test-only device config; no Rust fallback exists, so passing proves the script plumbing end to end - register jejoue/maxpro/script cases in the 8 matrices that run aneros (embedded/JSON x v1-v4); v0 blocks keep the multi-vibrator exclusion
… field note - crates/buttplug_server/docs/script-protocols.md: authoritative v1 script contract (metadata, init_state, handlers, command maps, error mapping, language subset and engine limits) with the shipped maxpro example - CHANGELOG: 11.1.0 entry for the rhai-protocols feature and new public APIs - buttplug_tests CLAUDE.md: document the script_protocol_directory YAML field - .gitignore: un-ignore crates/buttplug_server/docs (bare 'docs' rule is for generated book output)
- cfg(test)-gate the ScriptedProtocolHandler import in the loader - rely on auto-deref when binding the state guard to this - drop unused test fixture constant
- Replace the std package's sleep(INT)/sleep(FLOAT) with immediate errors: thread-blocking sleep consumes no operations and would bypass every budget (tests cover both load-time and handler-time rejection) - Route print/debug into the server log instead of raw stdout - Bound loading: max 1 MiB per script file, max 256 files per directory (excess skipped with structured reasons) - Set explicit engine caps for defined functions (1024) and live variables (1024) - Validate init_state() templates recursively against an allowlist of deeply-cloning value types, so per-connection state copies can never alias through shared cells or function pointers (regression tests: nested state isolation, FnPtr rejection) - Gate the whole script module out of wasm builds (feature + target cfg) - Record directory-entry inspection errors in the structured report instead of dropping them - Pin remaining conversion branches in tests: multi-command returns, Blob data, write_with_response, signed rotate/temperature dispatch, position-with-duration, and float-data rejection - Update docs with the new limits and behaviors
The not(target_arch = "wasm32") predicate on pub mod script was lost to a formatting cleanup; with it restored, enabling rhai-protocols on wasm no longer compiles the script module at all (the manager logs and ignores a configured directory there).
qdot
marked this pull request as draft
September 2, 2026 03:13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.